import javax.sound.sampled.Port;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class SocketServer {
    public static void main(String[] args){
        try {

            ServerSocket serverSocket = new ServerSocket(port:8888);
            Socket client = serverSocket.accept();
            System.out.println("客户端连接成功"+client.getInetAddress());


            InputStream inputStream= client.getInputStream();
            byte[] bytes = new byte[1024];
            int len;
            while ((len = inputStream.read(bytes))!=-1){
                System.out.println(new String(bytes));
            }
            Scanner scanner= new Scanner(System.in);
            String s = scanner.nextLine();
            OutputStream outputStream = client.getOutputStream();
            outputStream.write(s.getBytes());
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
